<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Services\WechatService;
use App\Services\JwtService;


class WechatController extends Controller
{
    public function login(Request $request)
    {
        $code = $request->code;
        $nick_name = $request->nick_name;
        $avatar_url = $request->avatar_url;

        $service = new WechatService();

        $user_id = $service->login($code,$nick_name,$avatar_url);
    
        $jwtService = new JwtService();

        $token =  $jwtService->createToken($user_id,'user');
        
        return ['code'=>200,'data'=>['token'=>$token]];
    }
}
